' This program exported from BASIC Anywhere Machine (Version [5.2.3].[2024.09.09.00.00]) on 2025.04.18 at 21:16 (Coordinated Universal Time)
' This program by Charlie Veniot is a port and mod of a program shared 
' by Antoni Gual Via in the "BASIC, QBasic, GWBasic computer programming" Facebook group
' (https://www.facebook.com/share/p/16SQ7gwtSF/)
' changes for BAM noted with 📌

' 📌 changed: SCREEN 12
SCREEN _NEWIMAGE( 600, 600, 17)

ALERT("Once rendered, a drawing will remain on the screen for about 3 seconds before the screen gets cleared for a new rendering.\n\n" + _
      "Click/touch the screen to pause the program until you release the click/touch.")

' 📌 not supported in BAM: WINDOW (-319, -239)-(320, 240)

TYPE P2D
  x AS SINGLE
  y AS SINGLE
END TYPE

' 📌 Moved and changed: npts = 6 + 2 * INT( RND * 5 ) 'ensure npoints are even
tris = 21
CONST coef = .95
invc = 1 - coef
CONST pi = 3.141592
CONST r = 240
DIM c(26) AS P2D ' 📌 changed: REDIM c(npts) AS P2D
DIM t(2) AS P2D
adj = 300 ' 📌 added to center image on the screen (does the job of the removed WINDOW statement)

a_new_drawing: ' 📌 Added

npts = 6 + 2 * INT( RND * 11 ) 'ensure npoints are even ' 📌 Moved here from above and changed
dang = 2 * pi / npts
ang = 0

c1 = INT( RND * 63 ) + 1 ' 📌 Added
c2 = IFF( INT(RND * 3) = 1, c1, INT( RND * 63 ) + 1 ) ' 📌 Added
c3 = IFF( INT(RND * 3) = 1, c2, INT( RND * 63 ) + 1 ) ' 📌 Added

'coords of point in a circle
FOR I = 0 TO npts - 1
    c(I).x = r * SIN(ang) + adj ' 📌 added adj
    c(I).y = r * COS(ang) + adj ' 📌 added adj
    ang = ang + dang
    PSET (c(I).x, c(I).y), 15
NEXT

c(npts).x = c(0).x: c(npts).y = c(0).y 'repeat first point in last

'FOR EACH SECTOR
FOR I = 1 TO npts
    'START FROM A POLYGON SIDE AN CENTER
    t(0).x = 0 + adj: t(0).y = 0 + adj  ' 📌 added adj to both assignment statements
    IF I AND 1 THEN
       t(1).x = c(I - 1).x: t(1).y = c(I - 1).y
       t(2).x = c(I).x: t(2).y = c(I).y
    ELSE 'SWAP VERTICES ON EVEN sectors
       t(1).x = c(I).x: t(1).y = c(I).y
       t(2).x = c(I - 1).x: t(2).y = c(I - 1).y
    END IF

    'FOR EACH ITERATION IN A SECTOR
    FOR j = 1 TO tris
        'DRAW THE TRIANGLE
        PSET (t(0).x, t(0).y)
        LINE -(t(1).x, t(1).y), c1  ' 📌 Added color
        LINE -(t(2).x, t(2).y), c2  ' 📌 Added color
        LINE -(t(0).x, t(0).y), c3  ' 📌 Added color
        ' 📌 Changed: IF j = tris THEN EXIT FOR
        ' BAM does not support "EXIT FOR", so I embedded the previous code below in and IF statement
        IF j <> tris THEN
           'CALCULATE a smaller INSCRIBED TRIANGLE
           ttx = t(0).x * invc + t(1).x * coef: tty = t(0).y * invc + t(1).y * coef
           t(1).x = t(1).x * invc + t(2).x * coef: t(1).y = t(1).y * invc + t(2).y * coef
           t(2).x = t(2).x * invc + t(0).x * coef: t(2).y = t(2).y * invc + t(0).y * coef
           t(0).x = ttx: t(0).y = tty
        END IF
        SLEEP 0.01 ' 📌 Added
    NEXT
NEXT

' 📌 Changed: SLEEP
SLEEP 3
IF _MOUSEBUTTON THEN WHILE _MOUSEBUTTON : WEND  ' 📌 Added
CLS ' 📌 Added
GOTO a_new_drawing ' 📌 Added